package cn.bdqn.sys.controller;


import cn.bdqn.sys.entity.User;
import cn.bdqn.sys.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhou
 * @since 2019-02-19
 */
@RestController
@RequestMapping("/sys/user")
public class UserController {
    @Autowired
    private IUserService iUserService;
    @GetMapping
    @RequiresRoles("admin")
    @RequestMapping("getlist")
    public Object getlist(){

        return iUserService.list(null);
    }
    @RequestMapping("/delete")
    @RequiresPermissions("sys:delete")
    public  String delete(Long id){
        iUserService.removeById(id);
        return "ok";
    }
    @RequestMapping("add")
    @RequiresPermissions("sys:add")
    public String add(){
        User user=new User();
        user.setName("test1");
        user.setAge(26);
        user.setEmail("6893@.com");
        user.setPassword("123456");
        iUserService.save(user);
        return "ok";
    }
}
